package com.hopu.blb_erp.controller;

import com.hopu.blb_erp.entity.Organization;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.Site;
import com.hopu.blb_erp.service.OrganizationService;
import com.hopu.blb_erp.service.SiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
public class SiteController {

    @Autowired
    private SiteService siteService;

    @ApiOperation("分页查询站点")
    @GetMapping("/sites/{current}/{pageSize}")
    public ResponseEntity<PageEntity> findPage(@PathVariable("current")Integer current, @PathVariable("pageSize")Integer pageSize){
        PageEntity<Site> page = siteService.findPage(current, pageSize);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("添加站点")
    @PostMapping("/site")
    public ResponseEntity<String> add(@RequestBody Site site){
        siteService.save(site);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("删除站点")
    @DeleteMapping("/site/{id}")
    public ResponseEntity<String> delete(@PathVariable("id") Long id){
        siteService.removeById(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("更新站点")
    @PutMapping("/site")
    public ResponseEntity<String> modify(@RequestBody Site site){
        siteService.updateById(site);
        return ResponseEntity.ok("ok");
    }
}
